package com.jnu.mydiary.calendar;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;



public class SquareRelativeLayout extends RelativeLayout {

    public SquareRelativeLayout(Context context) {
        super(context);
    }

    public SquareRelativeLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SquareRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

        // Children are just made to fill our space.
        int childWidthSize = getMeasuredWidth();

        //高度和宽度一样
        heightMeasureSpec   = MeasureSpec.makeMeasureSpec((int)(childWidthSize*(1.2f)), MeasureSpec.EXACTLY);
        widthMeasureSpec   = MeasureSpec.makeMeasureSpec((int)(childWidthSize*(1.0f)), MeasureSpec.EXACTLY);
        /*heightMeasureSpec   = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
        widthMeasureSpec   = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);*/
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}